package org.ligson.fwc.api.util.date;

import org.apache.commons.lang3.time.DateFormatUtils;

import java.text.*;
import java.util.Calendar;
import java.util.Date;

public class MyDateFormat extends DateFormat {
    static DateConverter dateConverter = new DateConverter();

    public MyDateFormat() {
        calendar = Calendar.getInstance();
        numberFormat = NumberFormat.getInstance();
    }

    @Override
    public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
        return new StringBuffer(DateFormatUtils.format(date, "yyyy-MM-dd HH:mm:ss"));
        //return new StringBuffer(date.getTime() + "");
    }


    @Override
    public Date parse(String source, ParsePosition pos) {
        return dateConverter.convert(source);
    }

    @Override
    public Date parse(String source) throws ParseException {
        return dateConverter.convert(source);
    }
}
